<template>
  <!-- 修改窗口 -->
  <a-modal v-model:visible="visible" title="修改平台管理员信息" @ok="execUpd">
    <a-form
      ref="fromRef"
      :model="updObj"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-typography-title style="text-align: center"
        >{{ updObj.m_id }}管理员信息</a-typography-title
      >
      <a-form-item label="名字">
        <a-input v-model:value="updObj.m_name" />
      </a-form-item>
      <a-form-item label="性别">
        <a-select v-model:value="updObj.m_sex" style="width: 160px">
          <a-select-option value="1">男</a-select-option>
          <a-select-option value="0">女</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="角色">
        <a-select v-model:value="updObj.m_status" style="width: 160px">
          <a-select-option value="admin">平台管理员</a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { ref, reactive } from "vue";
import { put, tip } from "@/common";

export default {
  setup(props, { emit }) {
    const fromRef = ref();
    const updObj = reactive({
      m_id: "",
      m_name: "",
      m_sex: "",
      m_status: "",
    });
    const visible = ref(false);

    const open = (record) => {
      updObj.m_id = record.m_id;
      updObj.m_name = record.m_name;
      updObj.m_sex = record.m_sex;
      updObj.m_status = record.m_status;
      console.log("record" + record);
      visible.value = true;
    };

    const execUpd = () => {
      console.log(updObj);
      //执行修改
      put("/security/admin", updObj).then((res) => {
        emit("ok");
        updObj.m_id = "";
        updObj.m_name = "";
        updObj.m_sex = "";
        updObj.m_status = "";
        visible.value = false;
        tip.success("修改管理员信息成功！");
      });
    };

    return {
      updObj,
      visible,
      execUpd,
      open,
      fromRef,
    };
  },
};
</script>
<style scoped>
</style>